#pragma once

#include <google/protobuf/descriptor.h>
#include <google/protobuf/message.h>
#include <google/protobuf/service.h>

#include "EZErrorCode.h"

class EZRPC_Ctl : public google::protobuf::RpcController
{
public:
	virtual void Reset(){
		err_code_ = std::error_code();
	}

	virtual bool Failed() const{ 
		return err_code_.value() == 0;
	}

	virtual std::string ErrorText() const{ 
		return err_code_.message();
	}

	virtual void StartCancel(){}

	virtual void SetFailed(const std::string& reason){}

	virtual bool IsCanceled() const{ 
		return true;
	}

	virtual void NotifyOnCancel(google::protobuf::Closure* callback){}

	void set_errinfo(std::error_code e){
		err_code_ = e;
	}

	void set_timeout(int t){
		timeout_ = t;
	}

	int	timeout() { 
		return timeout_; 
	}

	std::error_code errcode() { 
		return err_code_;
	}
private:
	std::error_code	err_code_;
	int			timeout_;
};

